from modelscope import Model
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.preprocessors import Preprocessor


#下载模型
#modelscope download --model 'iic/nlp_structbert_sentiment-classification_chinese-base' --include '*.*' --local_dir 'D:/aiproject/modelscope_model/iic/nlp_structbert_sentiment-classification_chinese-base'

# model_path = 'D:/aiproject/modelscope_model/iic/nlp_structbert_sentiment-classification_chinese-base'
model_path = 'D:/aiproject/modelscope_model/iic/nlp_structbert_backbone_base_std'
# 使用pipline
semantic_cls = pipeline(Tasks.text_classification , model_path)
out = semantic_cls(input='启动的时候很大声音，然后就会听到1.2秒的卡察的声音，类似齿轮摩擦的声音')
print(out)


# semantic_cls = Model.from_pretrained(model_path
#                                      ,task='text-classification')
# preprocessor=Preprocessor.from_pretrained(model_path)
# token = preprocessor("启动的时候很大声音，然后就会听到1.2秒的卡察的声音，类似齿轮摩擦的声音")
# # print(token)
# out=semantic_cls(**token)
# print(out)
